package com.feige.web.result;

import com.feige.base.po.IPersistence;
import com.feige.base.vo.BaseVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * @author feige
 */
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "返回分页")
@Data
public class PageResult<T extends IPersistence, R extends BaseVo> extends BaseResult{
    private static final long serialVersionUID = 4694907770420284705L;
    
    @ApiModelProperty(
            value = "分页信息"
    )
    private PageInfo<T> page;

    @ApiModelProperty(
            value = "返回值",
            example = "[]"
    )
    private List<R> data;

    public static  <T extends IPersistence, R extends BaseVo> PageResult<T, R > success(PageInfo<T> page, List<R> data){
        PageResult<T, R> result = new PageResult<>();
        result.setSuccess();
        result.setData(data);
        result.setPage(page);
        return result;
    }

    public static <T extends IPersistence, R extends BaseVo> PageResult<T, R >failure(PageInfo<T> page, List<R> data){
        PageResult<T, R> result = new PageResult<>();
        result.setFailure();
        result.setData(data);
        result.setPage(page);
        return result;
    }

    public static <T extends IPersistence, R extends BaseVo> PageResult<T, R > success(){
        return success(null, null);
    }
    public static <T extends IPersistence, R extends BaseVo> PageResult<T, R > failure(){
        return failure(null, null);
    }
    
}
